package com.hsc.www.reSend;

import java.util.List;

public class DelayedMessageHelper {


    public static final ThreadLocal<DelayedAndTryMessage> threadLocal = new ThreadLocal<>();

    /**
     * @param delayTime 延迟投递到消费队列的时长
     */
    public static void setDelayedMessage(Integer delayTime) {
        setDelayedMessage(delayTime, 0, null);
    }

    /**
     * @param totalAttempts 消费失败，总尝试次数
     * @param intervalTime  尝试间隔 单位：毫秒
     */
    public static void setDelayedMessage(Integer totalAttempts, List<Integer> delayedTimeList) {
        setDelayedMessage(0, totalAttempts, delayedTimeList);
    }

    /**
     * @param totalAttempts 消费失败，总尝试次数
     * @param delayedTimeList  尝试间隔 单位：秒
     */
    public static void setDelayedMessage(Integer delayTime, Integer totalAttempts, List<Integer> delayedTimeList) {
        DelayedAndTryMessage delayedAndTryMessage = new DelayedAndTryMessage();
        delayedAndTryMessage.setDelayTime(delayTime);
        delayedAndTryMessage.setTotalAttempts(totalAttempts);
        delayedAndTryMessage.setDelayedTimeList(delayedTimeList);
        threadLocal.set(delayedAndTryMessage);
    }

    public static DelayedAndTryMessage getDelayedMessage() {
        return threadLocal.get();
    }

    public static void clearDelayedMessage() {
        threadLocal.set(null);
    }
}
